package edu.fdzc.system.controller;

import com.github.pagehelper.PageInfo;
import edu.fdzc.system.common.Result;
import edu.fdzc.system.entity.ExamPlan;
import edu.fdzc.system.service.ExamPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/examPlan")
public class ExamPlanController {

    @Autowired
    private ExamPlanService examPlanService;

    @PostMapping("/add")
    public Result add(@RequestBody ExamPlan examPlan) {
        examPlanService.add(examPlan);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody ExamPlan examPlan) {
        examPlanService.updateById(examPlan);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        examPlanService.deleteById(id);
        return Result.success();
    }
    @DeleteMapping("/delete/batch")
    public Result deleteByIds(@RequestBody List<Integer> ids) {
        examPlanService.deleteByIds(ids);
        return Result.success();
    }

    @GetMapping("/selectById/{id}")
    public Result selectById(Integer id) {
        ExamPlan examPlan = examPlanService.selectById(id);
        return Result.success(examPlan);
    }

    @GetMapping("/selectAll")
    public Result selectAll(ExamPlan examPlan) {
        List<ExamPlan> list = examPlanService.selectAll(examPlan);
        return Result.success(list);
    }

    @GetMapping("/selectPage")
    public Result selectPage(ExamPlan examPlan,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize){
        PageInfo<ExamPlan> pageInfo = examPlanService.selectPage(examPlan,pageNum,pageSize);
        return Result.success(pageInfo);
    }


}
